//
//  LTPlayListView.m
//  聆听FM
//
//  Created by dllo on 16/6/15.
//  Copyright © 2016年 Dark. All rights reserved.
//

#import "LTPlayListView.h"
#import "LTUnPlayTableViewCell.h"
#import "ZCSListenListListModel.h"
#import "LTPlayTableViewCell.h"

@implementation LTPlayListView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40 * FITHEIGHT, frame.size.width, frame.size.height - 80 * FITHEIGHT)];
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
        self.tableView.separatorStyle = 0;
        [self addSubview:_tableView];
        [self.tableView registerNib:[UINib nibWithNibName:@"LTPlayListTopTableViewCell" bundle:nil] forCellReuseIdentifier:@"playListTop"];
        [self.tableView registerNib:[UINib nibWithNibName:@"LTPlayDownViewTableViewCell" bundle:nil] forCellReuseIdentifier:@"close"];
        [self.tableView registerNib:[UINib nibWithNibName:@"LTPlayTableViewCell" bundle:nil] forCellReuseIdentifier:@"play"];
        [self.tableView registerNib:[UINib nibWithNibName:@"LTUnPlayTableViewCell" bundle:nil] forCellReuseIdentifier:@"unPlay"];
        _topView = [_tableView dequeueReusableCellWithIdentifier:@"playListTop"];
        _topView.frame = CGRectMake(0, 0, frame.size.width, 40 * FITHEIGHT);
        [self addSubview:_topView];
        _downView = [_tableView dequeueReusableCellWithIdentifier:@"close"];
        _downView.frame = CGRectMake(0, frame.size.height - 40 * FITHEIGHT, SCREENWIDTH, 40 * FITHEIGHT);
        [self addSubview:_downView];
        
        //加载
        self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self getNext];
        }];
        
        
        
    }
    return self;
}
//加载
- (void)getNext
{
    [self.delegata getMoreData];
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 35 * FITHEIGHT;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  self.dataArray.count;
}

- (void)setDataArray:(NSMutableArray *)dataArray
{
    if (_dataArray != dataArray) {
        _dataArray = dataArray;
        [self.tableView reloadData];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZCSListenListListModel *model = [self.dataArray objectAtIndex:indexPath.row];
    if (self.onDid == indexPath.row) {
        LTPlayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"play"];
        cell.model = model;
        return cell;
        
    }
    else
    {
    LTUnPlayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"unPlay"];

    
    cell.model = model;
    
    return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.onDid = indexPath.row;
    [self.tableView reloadData];
    self.playListBlock(indexPath.row);
}



@end
